import { GSprite } from "../../../../../com/mui/controls/GSprite";
import { Global } from "../../../../../com/gengine/global/Global";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { PetIslandUtil } from "../PetIslandUtil";
import { SPlaceMiniInfo } from "../../../../../Message/Game/SPlaceMiniInfo";
import { ColorConfig } from "../../../resource/ColorConfig";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { EntityUtil } from "../../../scene/layer/utils/EntityUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { PetIslandStateData } from "../vo/PetIslandStateData";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { EffectManager } from "../../../manager/EffectManager";
import { CursorManager } from "../../../manager/CursorManager";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GBitmap } from "../../../../../com/mui/controls/GBitmap";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
type int = number;
//class PetIslandMapItem
    
    export  class PetIslandMapItem extends GSprite
    {
        constructor(arg1: int)
        {
            super();
            this._downPoint = new Object /* flash.geom.Point */();
            this._upPoint = new Object /* flash.geom.Point */();
            this._type = arg1;
            this.init();
            this.addEventListeners();
            return;
        }

        /* internal  */onMouseUpHandler(arg1: Object /* flash.events.MouseEvent */=null): void
        {
            this._upPoint.x = Global.stage.mouseX;
            this._upPoint.y = Global.stage.mouseY;
            if (this._data && (flash.geom.Point.distance(this._downPoint, this._upPoint) < 80 || arg1 == null)) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandMapGetPlaceInfo, this._data));
            }
            return;
        }

        /* internal  */onResCompl(): void
        {
            this._hasLoadCom = true;
            if (this._data) 
            {
                this.setPicData();
            }
            return;
        }

        /* internal  */setPicData(): void
        {
            this._pic.bitmapData = GlobalClass.getBitmapData("PetIslandMapSmallMapItem_" + this._type + this._data.pos.placeType);
            this._pic.x = (PetIslandUtil.MAP_SIZE - this._pic.width) / 2;
            this._pisSp.addChildAt(this._pic, 0);
            var loc1=PetIslandUtil.isInGuild(this._data.guildId);
            this.bg = loc1;
            return;
        }

        public set data(arg1: SPlaceMiniInfo)
        {
            this._data = arg1;
            if (arg1.guildId && arg1.guildId.id > 0) 
            {
                this._name.textColor = ColorConfig.instance.getItemColor(arg1.pos.placeType + 2).intColor;
                this._name.htmlText = HTMLUtil.removeHtml(PetIslandUtil.getPosName(arg1.pos, false)) + " [" + EntityUtil.getProxyName(arg1.guildId) + "]" + "<br>" + arg1.guildName;
            }
            else 
            {
                this._name.textColor = GlobalStyle.color1Uint;
                this._name.htmlText = HTMLUtil.removeHtml(PetIslandUtil.getPosName(arg1.pos, false)) + GameDefConfig.instance.getPetIslandPlaceTypeName(arg1.pos.placeType, 1);
            }
            if (this._hasLoadCom) 
            {
                this.setPicData();
            }
            var loc1=PetIslandUtil.getState(new PetIslandStateData(arg1.guildId, arg1.isFighting, arg1.protectSeconds));
            if (loc1 != "") 
            {
                this._nameSp.addChild(this._state);
                this._state.styleName = loc1;
            }
            else 
            {
                DisplayUtil.removeMe(this._state);
            }
            if (arg1.isFighting) 
            {
                this.setFilter([FilterConst.guidePetCall]);
            }
            else 
            {
                EffectManager.glowFilterUnReg(this._pic);
            }
            this.addEventListeners();
            return;
        }

        public setFilter(arg1: Array<any>=null): void
        {
            if (arg1 == null) 
            {
                this.onMouseUpHandler();
            }
            if (arg1 == null && this._data && this._data.isFighting) 
            {
                return;
            }
            EffectManager.glowFilterUnReg(this._pic);
            EffectManager.glowFilterReg(this._pic, arg1);
            return;
        }

        public clean(): void
        {
            EffectManager.glowFilterUnReg(this._pic);
            this._data = null;
            this._pic.bitmapData = null;
            this.removeEventListeners();
            return;
        }

        /* internal  */addEventListeners(): void
        {
            this._pisSp.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            this._pisSp.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
            this._pisSp.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMouseDownHandler);
            return;
        }

        /* internal  */removeEventListeners(): void
        {
            this._pisSp.removeEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            this._pisSp.removeEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
            this._pisSp.removeEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMouseDownHandler);
            return;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._data && this._data.isFighting) 
            {
                return;
            }
            EffectManager.glowFilterUnReg(this._pic);
            EffectManager.glowFilterReg(this._pic);
            CursorManager.hideCursor();
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */onMouseOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._data && this._data.isFighting) 
            {
                return;
            }
            EffectManager.glowFilterUnReg(this._pic);
            return;
        }

        /* internal  */onMouseDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._downPoint.x = Global.stage.mouseX;
            this._downPoint.y = Global.stage.mouseY;
            return;
        }

        /* internal  */set bg(arg1: Boolean)
        {
            if (arg1) 
            {
                this._nameBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetIslandMapMyIslandBg);
            }
            else 
            {
                this._nameBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetIslandMapOtherIslandBg);
            }
            this._nameSp.addChildAt(this._nameBg, 0);
            return;
        }

        public init(): void
        {
            this._pisSp = new Object /* flash.display.Sprite */();
            this.addChild(this._pisSp);
            this._pic = ObjCreate.createGBitmap("", 0, 0);
            this._nameSp = new Object /* flash.display.Sprite */();
            this._nameSp.mouseEnabled = false;
            this.addChild(this._nameSp);
            this._name = ObjCreate.createGTextField("", 0, 90, PetIslandUtil.MAP_SIZE, 60, this._nameSp, new GTextFormat(FontUtil.songtiName, 12, 11661311, null, null, null, null, null, flash.text.TextFormatAlign.CENTER, null, null, null, 4));
            this._name.multiline = true;
            this._name.wordWrap = true;
            this._name.mouseEnabled = false;
            this._state = ObjCreate.createGLoadedButton("", (PetIslandUtil.MAP_SIZE - 50) / 2, 20, 50, 50, this._nameSp);
            this._state.mouseEnabled = false;
            this._nameBg = ObjCreate.createGBitmap("", 0, 90, null);
            this._pisSp.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMouseUpHandler);
            LoaderHelp.addResCallBack(ResFileConst.PetIslandMap, this.onResCompl);
            return;
        }

        /* internal */ /* var */_type: int;

        /* internal */ /* var */_data: SPlaceMiniInfo;

        /* internal */ /* var */_pic: GBitmap;

        /* internal */ /* var */_pisSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_hasLoadCom: Boolean;

        /* internal */ /* var */_nameSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_nameBg: GBitmap;

        /* internal */ /* var */_name: GTextFiled;

        /* internal */ /* var */_state: GLoadedButton;

        /* internal */ /* var */_downPoint: Object /* flash.geom.Point */;

        /* internal */ /* var */_upPoint: Object /* flash.geom.Point */;
    }
